package codeRose.intercepter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import codeRose.domain.Customer;


public class LoginHandlerIntercepter implements HandlerInterceptor{
	//1执行handler之前进行的
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		/*//得到请求的URL
		String url = request.getRequestURI();
		if(url.indexOf("login")>=0){
			return true;
					}
		HttpSession session =request.getSession();
		Customer customer = (Customer)session.getAttribute("user");
		if(customer!=null){
			return true;
		}
		request.getRequestDispatcher("/login.jsp").forward(request, response);
		System.out.println("被拦截了");*/
		return true;
	}
	//2执行handler时，但在返回modelAndView之前
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		System.out.println("HandlerIntercepter1.........postHandle");
		
	}
	//3执行handler之后，在执行此方法。有异常
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		System.out.println("HandlerIntercepter1.........afterCompletion");
		
	}

}
